/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.ctrl.actor;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.actor.UntypedActorFactory;
import akka.routing.RoundRobinPool;
import akka.routing.RoundRobinRouter;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Administrator
 */
public class ActorManager {

    private static ActorManager actorManager;
    private Map<String, ActorRef> actors = new HashMap<String, ActorRef>();

    private ActorSystem system = ActorSystem.create("myActor");

    public static ActorManager getIntance() {
        if (actorManager == null) {
            actorManager = new ActorManager();

        }

        return actorManager;
    }

    public void initActor() {

        ActorRef sendDataActor = system.actorOf(Props.create(SendDataActor.class), "SendDataActor");
        ActorRef sendInfoToCenterActor = system.actorOf(Props.create(SendInfoToCenterActor.class), "SendInfoToCenterActor");
       
        actors.put("SendDataActor", sendDataActor);
        actors.put("SendInfoToCenterActor", sendInfoToCenterActor);
    }

    public ActorRef getActor(String actorName) {
        return actors.get(actorName);
    }

    public void destory() {
        for (String key : actors.keySet()) {
             system.stop( actors.get(key));
        }
        System.out.println("关闭akka");
        system.shutdown();

    }

}
